<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>localStorage的使用</title>
</head>

<body>
    <script>
        // 存入数据
        localStorage.setItem('username', '龚汉强')
        localStorage.setItem('password', '123456')
        // 获取数据
        console.log(localStorage.getItem('username'));
        console.log(localStorage.getItem('password'));
        // 删除单个数据
        localStorage.removeItem('password')
        // 删除所有数据
        // localStorage.clear()

        // 修改数据 存在 key 则修改 不存在则新建
        localStorage.setItem('username', '胡馨予')

        // 存储复杂数据类型，必须转换为json字符串类型存储
        const student = {
            stuName : '张三',
            gender: '男',
            age: 20
        }
        // 存入localStorage
        localStorage.setItem('student',JSON.stringify(student))
        // 将json字符串转换为复杂数据类型
        console.log(JSON.parse(localStorage.getItem('student')));
    </script>
</body>

</html>